Component({
  properties: {
    todo: {
      type: Object,
      value: {}
    },
    todoList: {
      type: Array,
      value: []
    }
  },

  data: {

  },

  methods: {
    changeTodoCheckbox(event) {
      const {id} = event.target.dataset
      const {todoList} = this.properties
      
      todoList.forEach(todo => {
        if (id === todo.id) {
          todo.done = !todo.done
        }
      })

      this.triggerEvent('updateData', {todoList})
    },

    deleteTodo(event) {
      const {id} = event.target.dataset
      let {todoList} = this.properties

      todoList = todoList.filter((todo) => {
        return todo.id !== id
      })
      
      this.triggerEvent('updateData', {todoList})
    },
  }
})